package com.epam.android.mailcomponent.contacts;

import java.util.List;

import com.epam.android.mailcomponent.R;

import android.app.ListActivity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class ContactsAdapter extends BaseAdapter {
	private Context context = null;
	private List<Contact> contactsList = null;

	public ContactsAdapter(ListActivity context, List<Contact> contactsList) {
		super();
		this.context = context;
		this.contactsList = contactsList;
	}

	@Override
	public int getCount() {
		return this.contactsList.size();
	}

	@Override
	public Object getItem(int position) {
		return (null == this.contactsList) ? null : this.contactsList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ContactsListView listView = (ContactsListView) convertView;
		if (null == listView) {
			listView = (ContactsListView) View.inflate(context, R.layout.contact_row,
					null);
		}
		listView.setContact(this.contactsList.get(position));
		return listView;
	}
}
